<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="https://cdn.bootcdn.net/ajax/libs/html2canvas/0.5.0-beta4/html2canvas.js"></script>
    <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
    <script>
        $(function () {
            html2canvas($("#ttt")[0]).then(function (canvas) {
                let url = canvas.toDataURL("image/png");
                $.ajax({
                    //请求方式
                    type : "POST",
                    dataType: "json",
                    //请求地址
                    url : "http://localhost:8080/res?savePng",
                    //数据，json字符串
                    data : {png:url},
                    //请求成功
                    success : function(result) {
                        console.log(result);
                    },
                    //请求失败，包含具体的错误信息
                    error : function(e){
                        console.log(e.status);
                        console.log(e.responseText);
                    }
                });
            })
        });
    </script>
    <title>上传</title>
</head>
<body>
<div id="ttt" style="background: red;color: white">test</div>
</body>
</html>